package com.qf.day33_test.controller;

import com.qf.day33_test.entity.Order;
import com.qf.day33_test.entity.Product;
import com.qf.day33_test.service.Service;
import com.qf.day33_test.vo.ResultVo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
public class EChartController {
    @Resource
    Service service;

    @RequestMapping("/bar")
    @ResponseBody
    public ResultVo doCharts() {
        final List<Product> proc = service.getProc();
        final List<Order> order = service.getOrder();

        final ArrayList<String> procName = new ArrayList<>();
        final ArrayList<Integer> sales = new ArrayList<>();

        for (Product product : proc) {
            procName.add(product.getProcName());
        }
        for (Order orders : order) {
            sales.add(orders.getSales());
        }
        return new ResultVo(procName, sales);
    }
}
